package com.mlnx.device.config;

import com.mlnx.device.session.SessionManagerFactory;
import com.mlnx.device.session.manager.MutilDeviceSessionManager;
import com.mlnx.device.session.manager.RedisSessionManager;
import com.mlnx.service.base.properties.DeviceSessionProperties;
import com.mlnx.service.base.properties.MutilDeviceProperties;

import org.shan.spring.redis.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by amanda.shan on 2019/10/31.
 */
@Configuration
public class DeviceConfig {

    @Autowired
    private MutilDeviceProperties mutilDeviceProperties;

    @Autowired
    private RedisUtil redisUtil;

    @Bean
    public MutilDeviceSessionManager sessionManager(){

        DeviceSessionProperties deviceSession = mutilDeviceProperties.getDeviceSession();

        RedisSessionManager redisSessionManager = new RedisSessionManager(redisUtil,
                deviceSession.getOnlineEcgKey());
        if (deviceSession.isClearSession()) {
            redisSessionManager.clear();
        }
        SessionManagerFactory.getInstance().setMutilDeviceSessionManager(redisSessionManager);

        return redisSessionManager;
    }

}
